/**
 * Created by abdulazizalonizi on 8/9/17.
 */
public class Fruit {

    String name ;
    double  stockQuantity;
    double pricePerKilogram;

    public Fruit (String name , double stockQuantity , double pricePerKilogram)
    {

        this.name = name ;
        this.stockQuantity = stockQuantity ;
        this.pricePerKilogram = pricePerKilogram ;

    }

    public Fruit (String name)
    {
     this(name ,0.0 , 0.0);

    }

    public String getName()
    {
        return this.name;
    }

    public double getStockQuantity()
    {
        return this.stockQuantity;
    }

    public double getPricePerKilogram()
    {
        return this.pricePerKilogram;
    }

    public void setStockQuantity (double  kilograms) throws IllegalArgumentException
    {
        if (kilograms < 0 )
            throw new IllegalArgumentException("Error : you entered invalid quantity!!");

        this.stockQuantity = kilograms ;
    }

    public void setPricePerKilogram(double price) throws IllegalArgumentException
    {
      if (price < 0 )
      {
          throw new IllegalArgumentException("Error : you entered invalid price!!");
      }

      this.pricePerKilogram =price;
    }

    public double sellFruit(double  kilograms) throws IllegalArgumentException
    {
        if (kilograms <= 0 )
            throw new IllegalArgumentException("Error : you entered invalid quantity!!");
        return (kilograms*this.pricePerKilogram);

    }

    public String toString()
    {
        return this.name+"          "+this.stockQuantity+"         "+this.pricePerKilogram;
    }

    public boolean equals(Object other)
    {
        if (other instanceof Fruit)
        {
           Fruit other_fruit = (Fruit) other ;
           if (other_fruit.getName().equals(this.name))
               return true ;
           else
               return false ;


        }
        else
            throw new IllegalArgumentException("Error : you entered wrong type!");

    }












}
